import { _decorator, Component, Node, Prefab, v3, __internal, Quat, quat, Vec3, RigidBodyComponent } from "cc";
const { ccclass, property } = _decorator;

@ccclass("Player")
export class Player extends Component {

    @property(Number)
    speed: number = 5;

    private _isClick: boolean = false;
    private _RegiBody: RigidBodyComponent = null;
    

    onLoad(){
        this._RegiBody = this.node.getComponent(RigidBodyComponent);
        this._RegiBody.setLinearVelocity(v3(-this.speed, 0, 0));
    }

    setIsClick(bool: boolean){
        this._isClick = bool;
        if (this._isClick) {
            // this.node.translate(v3(0, 0, -deltaTime * this.speed), Node.NodeSpace.WORLD);
            // this.node.rotate(Quat.fromEuler(quat(), -5, 0, 0), Node.NodeSpace.WORLD);
            this._RegiBody.setLinearVelocity(v3(0, 0, -this.speed));
        } else {
            // let rotate = v3();
            // this.node.getWorldRotation().getEulerAngles(rotate);
            // rotate.z += 5;
            // this.node.setRotation(Quat.fromEuler(quat(), rotate.x, rotate.y, rotate.z));
            // cc.log(rotate);
            // this.node.translate(v3(-deltaTime * this.speed, 0, 0), Node.NodeSpace.WORLD);
            // this.node.rotate(Quat.fromEuler(quat(), 0, 0, 5), Node.NodeSpace.WORLD);
            this._RegiBody.setLinearVelocity(v3(-this.speed, 0, 0));
        }
    }

    update(deltaTime: number){
        
    }
}
